package com.ease.platform.workbench.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ease.access.workbench.service.CoolBarAccessService;
import com.ease.access.workbench.service.CoolButtonAccessService;
import com.ease.access.workbench.service.CoolMenuAccessService;
import com.ease.access.workbench.service.CoolPerspectiveAccessService;
import com.ease.access.workbench.service.CoolPluginAccessService;
import com.ease.access.workbench.service.CoolViewAccessService;
import com.ease.model.term.CoolBar;
import com.ease.model.term.CoolButton;
import com.ease.model.term.CoolMenu;
import com.ease.model.term.CoolPerspective;
import com.ease.model.term.CoolPlugin;
import com.ease.model.term.CoolView;
import com.ease.platform.workbench.service.WorkbenchManagementService;

public class WorkbenchManagementServiceImpl /* extends AbstractNamespaceDataAccessServiceImpl */implements WorkbenchManagementService {

	private CoolPerspectiveAccessService coolPerspectiveAccessService;

	private CoolViewAccessService coolViewAccessService;

	private CoolPluginAccessService coolPluginAccessService;

	private CoolMenuAccessService coolMenuAccessService;

	private CoolButtonAccessService coolButtonAccessService;

	private CoolBarAccessService coolBarAccessService;

	public List<CoolPerspective> findCoolPerspectives() {
		// List<CoolPerspective> result = this.coolPerspectiveAccessService.findAll();
		List<CoolPerspective> coolPerspectives = this.coolPerspectiveAccessService.findEnabled();
		if (null != coolPerspectives) {
			for (CoolPerspective coolPerspective : coolPerspectives) {
				if (coolPerspective.getCoolPluginId() > 0) {
					CoolPlugin coolPlugin = coolPluginAccessService.findById(coolPerspective.getCoolPluginId());
					coolPerspective.setCoolPlugin(coolPlugin);
				}
			}
		}
		return coolPerspectives;
	}

	public List<CoolView> findCoolViews() {
		return this.coolViewAccessService.findAll();
	}

	public List<CoolBar> findCoolBarsByPerspectiveViewCode(String code) {
		CoolPerspective coolPerspective = this.coolPerspectiveAccessService.findByCode(code);
		CoolBar coolBar = this.coolBarAccessService.findById(coolPerspective.getCoolBarId());
		List<CoolButton> coolButtons = this.coolButtonAccessService.findByCoolbarId(coolPerspective.getCoolBarId());
		coolBar.setButtons(coolButtons);
		List<CoolBar> result = new ArrayList<CoolBar>();
		result.add(coolBar);
		return result;
	}

	@Override
	public List<CoolMenu> findMainMenusByPerspectiveViewCode(String code) {
		CoolPerspective coolPerspective = this.coolPerspectiveAccessService.findByCode(code);
		return this.coolMenuAccessService.findByParentId(coolPerspective.getCoolMenuId());
	}

	public CoolPerspectiveAccessService getCoolPerspectiveAccessService() {
		return coolPerspectiveAccessService;
	}

	public void setCoolPerspectiveAccessService(CoolPerspectiveAccessService coolPerspectiveAccessService) {
		this.coolPerspectiveAccessService = coolPerspectiveAccessService;
	}

	public CoolViewAccessService getCoolViewAccessService() {
		return coolViewAccessService;
	}

	public void setCoolViewAccessService(CoolViewAccessService coolViewAccessService) {
		this.coolViewAccessService = coolViewAccessService;
	}

	public void setCoolPluginAccessService(CoolPluginAccessService coolPluginAccessService) {
		this.coolPluginAccessService = coolPluginAccessService;
	}

	public CoolPluginAccessService getCoolPluginAccessService() {
		return coolPluginAccessService;
	}

	public CoolButtonAccessService getCoolButtonAccessService() {
		return coolButtonAccessService;
	}

	public void setCoolButtonAccessService(CoolButtonAccessService coolButtonAccessService) {
		this.coolButtonAccessService = coolButtonAccessService;
	}

	public CoolMenuAccessService getCoolMenuAccessService() {
		return coolMenuAccessService;
	}

	public void setCoolMenuAccessService(CoolMenuAccessService coolMenuAccessService) {
		this.coolMenuAccessService = coolMenuAccessService;
	}

	public CoolBarAccessService getCoolBarAccessService() {
		return coolBarAccessService;
	}

	public void setCoolBarAccessService(CoolBarAccessService coolBarAccessService) {
		this.coolBarAccessService = coolBarAccessService;
	}

}
